package com.ruge._05_springboot_web.config.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class MyExceptionAdvice {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Map<String, Object> myExceptionHandler(Exception ex) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 500);
        map.put("message", ex.toString());
        //map.put("method", myex.getMethod());
        //map.put("descinfo", myex.getDescinfo());
        //发生异常进行日志记录，写入数据库或者其他处理，此处省略
        return map;
    }
}
